package cn.wolfcode.wolf2w.job;

import cn.wolfcode.wolf2w.redis.service.IStrategyStatisVORedisService;
import cn.wolfcode.wolf2w.redis.util.RedisKeys;
import cn.wolfcode.wolf2w.redis.vo.StrategyStatisVO;
import cn.wolfcode.wolf2w.service.IStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 将redis中数据进行持久化
 */
@Component
public class RedisDataPersistenceJob {

    @Autowired
    private IStrategyStatisVORedisService strategyStatisVORedisService;
    @Autowired
    private IStrategyService strategyService;

    @Scheduled(cron = "0/10 * * * * ? ")
    public void doWork(){
        System.err.println("redis 持久化 - start");
        String pattern = RedisKeys.STRATEGY_STATIS_VO.join("*");
        List<StrategyStatisVO> vos = strategyStatisVORedisService.listStrategyVOByPattern(pattern);
        for (StrategyStatisVO vo:vos){
            strategyService.updateStatisVo(vo);
        }
        System.err.println("redis 持久化 - end");
    }







}
